define([
		"Backbone",
		"js/view/MenuItemView"
	], function(Backbone, MenuItemView) {

	return Backbone.View.extend({
		tagName: "ul",

		initialize: function() {
			console.log("MenuView - Initialize");
		},

		render: function() {
			console.log("MenuView - Render");
			var self = this;

			this.$el.empty();
			this.collection.each(function(model) {
				var view = new MenuItemView({
					model: model
				});
				self.$el.append(view.render().el);
			});

			return this;
		},

		setSelected: function(label) {
			var selected = this.collection.find(function(model) {
				return model.get("label") == label;
			});

			if (selected != null) {
				this.unselectSelected();
				this.selected = selected;
				this.selected.set("selected", true);
			}
		},

		unselectSelected: function() {
			if (this.selected != null) {
				this.selected.set("selected", false);
			}
		}
	});
});